package com.kxr.day09.servlet;

import com.kxr.day09.dao.NewsDao;
import com.kxr.day09.entity.News;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/list")
public class NewsListServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String keywords = req.getParameter("keywords");
        System.out.println(keywords);
        NewsDao dao = new NewsDao();
        List<News> list = dao.search(keywords);
        req.setAttribute("list", list);
        req.getRequestDispatcher("/newsList.jsp").forward(req, resp);
    }
}
